package com.baseweb.webadmin.core.util;

import java.io.IOException;
import java.io.InputStream;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * xml文件处理工具类.
 */
public  final class XmlUtil {
	
	/**日志.
	 * 
	 */
	private static final Logger LOG = LoggerFactory.getLogger(XmlUtil.class);
	
	/**构造函数.
	 * 
	 */
	private XmlUtil() {
		
	}

	/**根据xml文件名获取xml文件的根节点的信息.
	 * @param xmlFileName xml配置文件名
	 * @return 返回xml文件的根节点
	 */
	public  static  Element  getRootElement(final String xmlFileName) {
		Thread currentThread = Thread.currentThread();
		ClassLoader  loader = currentThread.getContextClassLoader();
		final InputStream inputStream = loader.getResourceAsStream(xmlFileName);
		final SAXBuilder builder = new SAXBuilder(); 
		Element  foo = null;
		Document doc = null;
		try {
			doc = builder.build(inputStream);
			foo = doc.getRootElement();		 
		} catch (Exception e) {
			LOG.error("getRootElement", e);
		} 
		
		return foo;
		 
	}
	
	/**测试调用主方法.
	 * 
	 * @param args  参数
	 */
	public static void main(final String[]  args) {

	} 
}
